package com.lanou.controller;

import com.lanou.entity.ConsultantLevel;
import com.lanou.service.ConsultantLevelService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantLevelController
 * @Description TODO
 * @Author chenzhaobao
 * @Date 2025年08月13日 11:18
 * @Version 1.0
 */
@RestController
@RequestMapping("/consultantLevel")
public class ConsultantLevelController {

    @Autowired
    private ConsultantLevelService consultantLevelService;

    /**
     * 新增咨询师等级
     */
    @PostMapping
    public R addConsultantLevel(@RequestBody ConsultantLevel level) {
        int result = consultantLevelService.addConsultantLevel(level);
        return result > 0 ? R.ok("咨询师等级添加成功") : R.fail("咨询师等级添加失败");
    }

    /**
     * 根据ID删除咨询师等级
     */
    @DeleteMapping("/{id}")
    public R deleteConsultantLevel(@PathVariable Integer id) {
        int result = consultantLevelService.deleteConsultantLevelById(id);
        return result > 0 ? R.ok("咨询师等级删除成功") : R.fail("咨询师等级删除失败");
    }


    /**
     * 更新咨询师等级
     */
    @PutMapping
    public R updateConsultantLevel(@RequestBody ConsultantLevel level) {
        int result = consultantLevelService.updateConsultantLevel(level);
        return result > 0 ? R.ok("咨询师等级更新成功") : R.fail("咨询师等级更新失败");
    }

    /**
     * 根据ID查询咨询师等级
     */
    @GetMapping("/{id}")
    public R getConsultantLevelById(@PathVariable Integer id) {
        ConsultantLevel level = consultantLevelService.getConsultantLevelById(id);
        return level != null ? R.ok(level) : R.fail("未查询到咨询师等级信息");
    }

    /**
     * 查询所有咨询师等级
     */
    @GetMapping
    public R getAllConsultantLevels() {
        List<ConsultantLevel> levels = consultantLevelService.getAllConsultantLevels();
        return R.ok(levels);
    }
}
